package com.jixi.controller;

import com.jixi.common.result.PageResult;
import com.jixi.common.result.Result;
import com.jixi.pojo.dto.SchoolRegisterDto;
import com.jixi.pojo.entity.School;
import com.jixi.service.CooperateSchoolCompanyService;
import com.jixi.service.SchoolService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/education")
public class SchoolController {
	
	@Autowired
	private SchoolService schoolService;
	
	@Autowired
	private CooperateSchoolCompanyService cooperateSchoolCompanyService;
	
	/**
	 * 学校注册
	 *
	 * @param schoolRegisterDto 注册信息
	 * @return 注册结果
	 */
	@PostMapping("/school/register")
	public Result schoolRegister(@RequestBody SchoolRegisterDto schoolRegisterDto) {
		return schoolService.schoolRegister(schoolRegisterDto);
	}
	
	/**
	 * 学校列表
	 *
	 * @param pageNum       页码
	 * @param pageSize      每页数量
	 * @param schoolName    学校名
	 * @param principalName 负责人名
	 * @param status        状态
	 * @return 学校列表
	 */
	@GetMapping("/school/list")
	public Result<PageResult> schoolList(
			Integer pageNum,
			Integer pageSize,
			String schoolName,
			String principalName,
			Integer status
	) {
		return schoolService.schoolPage(pageNum,pageSize,schoolName,principalName,status);
	}
	
	/**
	 * 学校详情
	 *
	 * @param schoolId 学校id
	 * @return 学校详情
	 */
	@GetMapping("/school/info")
	public Result<School> getInfo(Long schoolId) {
		School school = schoolService.getSchoolInfoById(schoolId);
		return Result.success(school);
	}
	
	/**
	 * 学校重置密码
	 *
	 * @param schoolId      学校id
	 * @param resetPassword 重置的密码
	 * @return 重置密码结果
	 */
	@PutMapping("/school/resetPassword")
	public Result resetPassword(Long schoolId, String resetPassword) {
		return schoolService.schoolResetPassword(schoolId,resetPassword);
	}
	
	/**
	 * 学校状态修改
	 *
	 * @param schoolId 学校id
	 * @param status   状态
	 * @return 修改结果
	 */
	@PutMapping("/school/status")
	public Result updateStatus(Long schoolId, Integer status) {
		return schoolService.updateSchoolStatus(schoolId,status);
	}
	
	/**
	 * 获取学校的启用合作数
	 *
	 * @param schoolId 学校id
	 * @return 学校合作数
	 */
	@GetMapping("/school/cooperateNum")
	public Result<Long> getSchoolCooperateNum(Long schoolId) {
		return Result.success(cooperateSchoolCompanyService.countSchoolCooperateNum(schoolId));
	}
	
	/**
	 * 学校删除
	 *
	 * @param schoolId 学校id
	 * @return 删除结果
	 */
	@DeleteMapping("/school/delete")
	public Result delete(Long schoolId) {
		return schoolService.deleteSchoolById(schoolId);
	}
	
	/**
	 * 学校修改入账账户
	 *
	 * @param schoolId  学校id
	 * @param accountId 账户id
	 * @return 修改结果
	 */
	@PutMapping("/school/updateAccount")
	public Result updateAccount(Long schoolId, Long accountId) {
		return schoolService.updateSchoolAccount(schoolId,accountId);
	}
	
}
